<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智能行政区划身份证生成器</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
            color: #f0f0f0;
            min-height: 100vh;
            padding: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        .container {
            width: 95%;
            max-width: 1000px;
            background: rgba(25, 35, 45, 0.9);
            border-radius: 18px;
            box-shadow: 0 15px 45px rgba(0, 0, 0, 0.6);
            overflow: hidden;
            padding: 30px;
            position: relative;
            border: 1px solid rgba(100, 150, 200, 0.3);
        }
        
        header {
            text-align: center;
            margin-bottom: 30px;
            padding-bottom: 20px;
            border-bottom: 1px solid rgba(100, 150, 200, 0.3);
        }
        
        h1 {
            background: linear-gradient(90deg, #4ca1af, #c4e0e5);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-size: 3rem;
            margin-bottom: 15px;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
        }
        
        .subtitle {
            color: #a0c8e0;
            font-size: 1.3rem;
            margin-top: 10px;
            max-width: 700px;
            margin: 0 auto;
            line-height: 1.6;
        }
        
        .controls {
            display: flex;
            flex-wrap: wrap;
            gap: 25px;
            margin-bottom: 30px;
            background: rgba(30, 45, 60, 0.7);
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
            border: 1px solid rgba(80, 130, 180, 0.3);
        }
        
        .control-group {
            flex: 1;
            min-width: 220px;
        }
        
        .control-row {
            display: flex;
            gap: 20px;
            flex-wrap: wrap;
            margin-bottom: 15px;
        }
        
        .control-row .control-group {
            flex: 1;
            min-width: 200px;
        }
        
        label {
            display: block;
            margin-bottom: 12px;
            font-weight: 600;
            color: #8ab3cf;
            font-size: 1.15rem;
        }
        
        select, button, input {
            width: 100%;
            padding: 16px 20px;
            border-radius: 12px;
            border: 1px solid rgba(80, 130, 180, 0.5);
            font-size: 1.1rem;
            background: rgba(20, 30, 40, 0.7);
            transition: all 0.4s;
            color: #e0f0ff;
            box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.4);
        }
        
        select {
            background-image: linear-gradient(45deg, transparent 50%, #4ca1af 50%),
                              linear-gradient(135deg, #4ca1af 50%, transparent 50%);
            background-position: calc(100% - 25px) center, calc(100% - 20px) center;
            background-size: 8px 8px, 8px 8px;
            background-repeat: no-repeat;
            appearance: none;
            cursor: pointer;
        }
        
        select:focus, input:focus {
            outline: none;
            border-color: #4ca1af;
            box-shadow: 0 0 0 4px rgba(76, 161, 175, 0.3);
        }
        
        button {
            background: linear-gradient(to right, #4ca1af, #2c3e50);
            color: white;
            font-weight: bold;
            border: none;
            cursor: pointer;
            margin-top: 10px;
            font-size: 1.25rem;
            letter-spacing: 1px;
            text-transform: uppercase;
            box-shadow: 0 6px 20px rgba(44, 62, 80, 0.5);
            transition: all 0.4s ease;
        }
        
        button:hover {
            background: linear-gradient(to right, #5cb1bf, #3c4e60);
            transform: translateY(-4px);
            box-shadow: 0 10px 25px rgba(44, 62, 80, 0.7);
        }
        
        button:active {
            transform: translateY(1px);
        }
        
        .result-container {
            background: rgba(30, 45, 60, 0.7);
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
            margin-top: 20px;
            border: 1px solid rgba(80, 130, 180, 0.3);
        }
        
        .result-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
            padding-bottom: 20px;
            border-bottom: 1px solid rgba(100, 150, 200, 0.3);
        }
        
        .result-header h2 {
            color: #4ca1af;
            font-size: 1.9rem;
            text-shadow: 0 2px 3px rgba(0, 0, 0, 0.3);
        }
        
        .result-count {
            background: #4ca1af;
            color: white;
            padding: 10px 20px;
            border-radius: 25px;
            font-size: 1.1rem;
            font-weight: bold;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
        }
        
        .id-card-list {
            list-style: none;
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
            gap: 20px;
        }
        
        .id-card-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 18px 22px;
            background: rgba(20, 30, 40, 0.6);
            border-radius: 12px;
            box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
            transition: all 0.4s;
            border-left: 4px solid #4ca1af;
            position: relative;
            overflow: hidden;
        }
        
        .id-card-item:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
            border-left: 4px solid #c4e0e5;
            background: rgba(25, 40, 55, 0.8);
        }
        
        .id-number {
            font-family: 'Courier New', monospace;
            font-size: 1.35rem;
            letter-spacing: 1.5px;
            font-weight: bold;
            color: #c4e0e5;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
        }
        
        .copy-btn {
            background: rgba(76, 161, 175, 0.8);
            color: white;
            border: none;
            border-radius: 8px;
            padding: 10px 18px;
            cursor: pointer;
            font-size: 1rem;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            gap: 8px;
            box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
        }
        
        .copy-btn:hover {
            background: rgba(92, 177, 191, 1);
            transform: scale(1.05);
        }
        
        .copy-btn.copied {
            background: #2c5364;
        }
        
        .disclaimer {
            margin-top: 30px;
            padding: 25px;
            background: rgba(44, 83, 100, 0.5);
            border-radius: 12px;
            border-left: 4px solid #4ca1af;
            font-size: 1rem;
            color: #b0d0e0;
            line-height: 1.6;
        }
        
        .disclaimer h3 {
            color: #c4e0e5;
            margin-bottom: 15px;
            font-size: 1.3rem;
        }
        
        footer {
            text-align: center;
            margin-top: 30px;
            padding-top: 25px;
            color: #7a9fb6;
            font-size: 1rem;
            border-top: 1px solid rgba(100, 150, 200, 0.3);
        }
        
        @media (max-width: 850px) {
            .id-card-list {
                grid-template-columns: 1fr;
            }
            
            .control-row {
                flex-direction: column;
                gap: 25px;
            }
            
            h1 {
                font-size: 2.4rem;
            }
            
            .controls {
                padding: 20px;
            }
        }
        
        .decoration {
            position: absolute;
            border-radius: 50%;
            background: rgba(76, 161, 175, 0.1);
            z-index: -1;
            animation: float 15s infinite linear;
        }
        
        .decoration-1 {
            top: -100px;
            right: -100px;
            width: 250px;
            height: 250px;
        }
        
        .decoration-2 {
            bottom: -120px;
            left: -120px;
            width: 300px;
            height: 300px;
            background: rgba(44, 83, 100, 0.15);
            animation-duration: 20s;
        }
        
        .decoration-3 {
            top: 40%;
            left: 10%;
            width: 80px;
            height: 80px;
            background: rgba(196, 224, 229, 0.15);
            animation-duration: 12s;
            animation-direction: reverse;
        }
        
        @keyframes float {
            0% { transform: translate(0, 0) rotate(0deg); }
            25% { transform: translate(10px, 10px) rotate(90deg); }
            50% { transform: translate(0, 20px) rotate(180deg); }
            75% { transform: translate(-10px, 10px) rotate(270deg); }
            100% { transform: translate(0, 0) rotate(360deg); }
        }
        
        .id-card-item::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(to right, #4ca1af, #c4e0e5);
            transform: scaleX(0);
            transform-origin: left;
            transition: transform 0.4s;
        }
        
        .id-card-item:hover::before {
            transform: scaleX(1);
        }
        
        .info-text {
            color: #8ab3cf;
            font-size: 0.95rem;
            margin-top: 8px;
            font-style: italic;
        }
        
        .manual-input {
            margin-top: 15px;
        }
        
        .input-group {
            margin-bottom: 15px;
        }
        
        .toggle-method {
            text-align: center;
            margin: 15px 0;
            color: #8ab3cf;
            cursor: pointer;
            text-decoration: underline;
        }
        
        .toggle-method:hover {
            color: #c4e0e5;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="decoration decoration-1"></div>
        <div class="decoration decoration-2"></div>
        <div class="decoration decoration-3"></div>
        
        <header>
            <h1>智能行政区划身份证生成器</h1>
            <p class="subtitle">根据选择的行政区划级别智能生成身份证：选择省份生成全省随机身份证，选择城市生成全市随机身份证，选择区县生成该区县身份证</p>
        </header>
        
        <div class="controls">
            <div id="autoMethod">
                <div class="control-row">
                    <div class="control-group">
                        <label for="province">选择省份：</label>
                        <select id="province">
                            <option value="">--请选择省份--</option>
                        </select>
                        <p class="info-text">仅选省份：生成该省所有区县的随机身份证</p>
                    </div>
                    
                    <div class="control-group">
                        <label for="city">选择城市：</label>
                        <select id="city" disabled>
                            <option value="">--请先选择省份--</option>
                        </select>
                        <p class="info-text">选择城市：生成该市所有区县的随机身份证</p>
                    </div>
                    
                    <div class="control-group">
                        <label for="district">选择区县：</label>
                        <select id="district" disabled>
                            <option value="">--请先选择城市--</option>
                        </select>
                        <p class="info-text">选择区县：生成该区县的身份证</p>
                    </div>
                </div>
                
                <div class="toggle-method" id="switchToManual">切换到手动输入区县代码</div>
            </div>
            
            <div id="manualMethod" style="display: none;width: 100%;">
                <div class="control-group">
                    <label for="manualDistrict">手动输入6位区县代码：</label>
                    <input type="text" id="manualDistrict" maxlength="6" placeholder="例如：110105">
                    <p class="info-text">直接输入6位行政区划代码，将忽略上面的选择</p>
                </div>
                
                <div class="toggle-method" id="switchToAuto">切换到行政区划选择</div>
            </div>
            
            <div class="control-row">
                <div class="control-group">
                    <label for="gender">性别：</label>
                    <select id="gender">
                        <option value="any">随机</option>
                        <option value="male">男</option>
                        <option value="female">女</option>
                    </select>
                </div>
                
                <div class="control-group">
                    <label for="age">年龄范围：</label>
                    <select id="age">
                        <option value="18-30">18-30岁</option>
                        <option value="31-45">31-45岁</option>
                        <option value="46-60">46-60岁</option>
                        <option value="18-60">18-60岁</option>
                        <option value="any" selected>随机</option>
                    </select>
                </div>
                
                <div class="control-group">
                    <label for="count">生成数量：</label>
                    <select id="count">
                        <option value="5">5条</option>
                        <option value="10" selected>10条</option>
                        <option value="15">15条</option>
                        <option value="20">20条</option>
                    </select>
                </div>
            </div>
            
            <button id="generate">
                <span>生成身份证号码</span>
            </button>
        </div>
        
        <div class="result-container">
            <div class="result-header">
                <h2>生成的身份证号码</h2>
                <span class="result-count">10 条</span>
            </div>
            <ul class="id-card-list" id="idCardList">
                <!-- 身份证号将通过JS动态生成 -->
            </ul>
        </div>
        
        <div class="disclaimer">
            <h3>使用说明与免责声明</h3>
            <p>1. 本工具提供两种方式生成身份证：行政区划选择或手动输入6位区县代码</p>
            <p>2. 生成的身份证号码仅用于测试和学习目的，符合国家标准GB11643-1999的校验规则</p>
            <p>3. 请勿将这些号码用于非法活动。根据《中华人民共和国居民身份证法》，冒用他人身份证件是违法行为</p>
            <p>4. 所有生成的身份证号码均为随机生成，如有雷同，纯属巧合</p>
        </div>
        
        <footer>
            <p>© 2025 智能行政区划身份证生成器 | 仅用于测试目的 | 数据来源于公开行政区划代码</p>
        </footer>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 模拟行政区划数据（实际应用中可使用更完整的数据）
            const regions = {
                "北京市": {
                    "code": "110000",
                    "cities": {
                        "北京市": {
                            "code": "110100",
                            "districts": {
                                "东城区": "110101",
                                "西城区": "110102",
                                "朝阳区": "110105",
                                "海淀区": "110108",
                                "丰台区": "110106",
                                "石景山区": "110107",
                                "门头沟区": "110109"
                            }
                        }
                    }
                },
                "上海市": {
                    "code": "310000",
                    "cities": {
                        "上海市": {
                            "code": "310100",
                            "districts": {
                                "黄浦区": "310101",
                                "徐汇区": "310104",
                                "长宁区": "310105",
                                "静安区": "310106",
                                "普陀区": "310107",
                                "虹口区": "310109",
                                "杨浦区": "310110",
                                "浦东新区": "310115"
                            }
                        }
                    }
                },
                "广东省": {
                    "code": "440000",
                    "cities": {
                        "广州市": {
                            "code": "440100",
                            "districts": {
                                "越秀区": "440104",
                                "海珠区": "440105",
                                "天河区": "440106",
                                "白云区": "440111",
                                "黄埔区": "440112",
                                "番禺区": "440113",
                                "花都区": "440114"
                            }
                        },
                        "深圳市": {
                            "code": "440300",
                            "districts": {
                                "罗湖区": "440303",
                                "福田区": "440304",
                                "南山区": "440305",
                                "宝安区": "440306",
                                "龙岗区": "440307",
                                "盐田区": "440308",
                                "龙华区": "440309"
                            }
                        },
                        "珠海市": {
                            "code": "440400",
                            "districts": {
                                "香洲区": "440402",
                                "斗门区": "440403",
                                "金湾区": "440404"
                            }
                        }
                    }
                },
                "浙江省": {
                    "code": "330000",
                    "cities": {
                        "杭州市": {
                            "code": "330100",
                            "districts": {
                                "上城区": "330102",
                                "拱墅区": "330105",
                                "西湖区": "330106",
                                "滨江区": "330108",
                                "萧山区": "330109",
                                "余杭区": "330110"
                            }
                        },
                        "宁波市": {
                            "code": "330200",
                            "districts": {
                                "海曙区": "330203",
                                "江北区": "330205",
                                "北仑区": "330206",
                                "镇海区": "330211",
                                "鄞州区": "330212"
                            }
                        },
                        "温州市": {
                            "code": "330300",
                            "districts": {
                                "鹿城区": "330302",
                                "龙湾区": "330303",
                                "瓯海区": "330304",
                                "洞头区": "330305"
                            }
                        }
                    }
                },
                "江苏省": {
                    "code": "320000",
                    "cities": {
                        "南京市": {
                            "code": "320100",
                            "districts": {
                                "玄武区": "320102",
                                "秦淮区": "320104",
                                "建邺区": "320105",
                                "鼓楼区": "320106",
                                "浦口区": "320111",
                                "栖霞区": "320113"
                            }
                        },
                        "苏州市": {
                            "code": "320500",
                            "districts": {
                                "虎丘区": "320505",
                                "吴中区": "320506",
                                "相城区": "320507",
                                "姑苏区": "320508",
                                "吴江区": "320509"
                            }
                        },
                        "无锡市": {
                            "code": "320200",
                            "districts": {
                                "锡山区": "320205",
                                "惠山区": "320206",
                                "滨湖区": "320211",
                                "梁溪区": "320213"
                            }
                        }
                    }
                },
                "四川省": {
                    "code": "510000",
                    "cities": {
                        "成都市": {
                            "code": "510100",
                            "districts": {
                                "锦江区": "510104",
                                "青羊区": "510105",
                                "金牛区": "510106",
                                "武侯区": "510107",
                                "成华区": "510108",
                                "龙泉驿区": "510112"
                            }
                        },
                        "绵阳市": {
                            "code": "510700",
                            "districts": {
                                "涪城区": "510703",
                                "游仙区": "510704",
                                "安州区": "510705"
                            }
                        },
                        "乐山市": {
                            "code": "511100",
                            "districts": {
                                "市中区": "511102",
                                "沙湾区": "511111",
                                "五通桥区": "511112"
                            }
                        }
                    }
                }
            };

            // 获取DOM元素
            const provinceSelect = document.getElementById('province');
            const citySelect = document.getElementById('city');
            const districtSelect = document.getElementById('district');
            const manualDistrictInput = document.getElementById('manualDistrict');
            const generateBtn = document.getElementById('generate');
            const idCardList = document.getElementById('idCardList');
            const resultCount = document.querySelector('.result-count');
            const countSelect = document.getElementById('count');
            const autoMethod = document.getElementById('autoMethod');
            const manualMethod = document.getElementById('manualMethod');
            const switchToManual = document.getElementById('switchToManual');
            const switchToAuto = document.getElementById('switchToAuto');

            // 切换输入方式
            switchToManual.addEventListener('click', function() {
                // 清空自动选择的值
                provinceSelect.value = '';
                citySelect.innerHTML = '<option value="">--请选择城市--</option>';
                citySelect.disabled = true;
                districtSelect.innerHTML = '<option value="">--请选择区县--</option>';
                districtSelect.disabled = true;
                
                autoMethod.style.display = 'none';
                manualMethod.style.display = 'block';
                manualDistrictInput.focus(); // 自动聚焦到输入框
            });
            
            switchToAuto.addEventListener('click', function() {
                // 清空手动输入的值
                manualDistrictInput.value = '';
                
                manualMethod.style.display = 'none';
                autoMethod.style.display = 'block';
				provinceSelect.disabled = false;
				citySelect.disabled = false;
				districtSelect.disabled = false;
            });
            
            // 手动输入框变化时，如果有值则禁用自动选择
            manualDistrictInput.addEventListener('input', function() {
                if (this.value && this.value.length === 6) {
                    provinceSelect.disabled = true;
                    citySelect.disabled = true;
                    districtSelect.disabled = true;
                } else {
                    provinceSelect.disabled = false;
                    // 根据当前选择状态设置城市和区县的选择框状态
                    if (provinceSelect.value) {
                        citySelect.disabled = false;
                    }
                    if (citySelect.value) {
                        districtSelect.disabled = false;
                    }
                }
            });
            
            

            // 初始化省份选择
            for (const province in regions) {
                const option = document.createElement('option');
                option.value = regions[province].code;
                option.textContent = province;
                provinceSelect.appendChild(option);
            }

            // 省份变化事件
            provinceSelect.addEventListener('change', function() {
				if (this.value) {
				    manualDistrictInput.value = '';
				}
                const provinceCode = this.value;
                const provinceName = this.options[this.selectedIndex]?.text;
                
                citySelect.innerHTML = '<option value="">--请选择城市--</option>';
                districtSelect.innerHTML = '<option value="">--请选择区县--</option>';
                districtSelect.disabled = true;
                
                if (!provinceCode || !provinceName) {
                    citySelect.disabled = true;
                    return;
                }
                
                citySelect.disabled = false;
                const cities = regions[provinceName].cities;
                
                for (const city in cities) {
                    const option = document.createElement('option');
                    option.value = cities[city].code;
                    option.textContent = city;
                    citySelect.appendChild(option);
                }
            });

            // 城市变化事件
            citySelect.addEventListener('change', function() {
				if (this.value) {
				    manualDistrictInput.value = '';
				}
                const cityCode = this.value;
                const cityName = this.options[this.selectedIndex]?.text;
                const provinceName = provinceSelect.options[provinceSelect.selectedIndex]?.text;
                
                districtSelect.innerHTML = '<option value="">--请选择区县--</option>';
                
                if (!cityCode || !cityName || !provinceName) {
                    districtSelect.disabled = true;
                    return;
                }
                
                districtSelect.disabled = false;
                const districts = regions[provinceName].cities[cityName].districts;
                
                for (const district in districts) {
                    const option = document.createElement('option');
                    option.value = districts[district];
                    option.textContent = district;
                    districtSelect.appendChild(option);
                }
            });

            // 获取当前选中的所有可用区县代码
            function getAvailableDistricts() {
                // 优先使用手动输入的区县代码
                if (manualDistrictInput.value && /^\d{6}$/.test(manualDistrictInput.value)) {
                    return [manualDistrictInput.value];
                }
                
                const provinceName = provinceSelect.options[provinceSelect.selectedIndex]?.text;
                const cityName = citySelect.options[citySelect.selectedIndex]?.text;
                const districtCode = districtSelect.value;
                
                // 如果选择了区县，则只返回该区县
                if (districtCode) {
                    return [districtCode];
                }
                
                // 如果选择了城市，则返回该城市下所有区县
                if (cityName && provinceName) {
                    const city = regions[provinceName]?.cities[cityName];
                    if (city) {
                        return Object.values(city.districts);
                    }
                }
                
                // 如果只选择了省份，则返回该省份下所有区县
                if (provinceName) {
                    const districts = [];
                    const cities = regions[provinceName]?.cities;
                    if (cities) {
                        for (const city in cities) {
                            const cityDistricts = Object.values(cities[city].districts);
                            districts.push(...cityDistricts);
                        }
                    }
                    return districts;
                }
                
                return [];
            }

            // 身份证最后一位校验码计算
            function calculateCheckDigit(id17) {
                // 加权因子
                const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
                // 校验码对应值
                const checkCodes = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
                
                let sum = 0;
                for (let i = 0; i < 17; i++) {
                    sum += parseInt(id17[i]) * weights[i];
                }
                
                return checkCodes[sum % 11];
            }
            
            // 生成随机出生日期
            function generateBirthdate(ageRange) {
                let minYear, maxYear;
                const currentYear = new Date().getFullYear();
                
                switch(ageRange) {
                    case '18-30':
                        minYear = currentYear - 30;
                        maxYear = currentYear - 18;
                        break;
                    case '31-45':
                        minYear = currentYear - 45;
                        maxYear = currentYear - 31;
                        break;
                    case '46-60':
                        minYear = currentYear - 60;
                        maxYear = currentYear - 46;
                        break;
                    case '18-60':
                        minYear = currentYear - 60;
                        maxYear = currentYear - 18;
                        break;
                    default: // any
                        minYear = currentYear - 80;
                        maxYear = currentYear - 18;
                }
                
                const year = Math.floor(Math.random() * (maxYear - minYear + 1)) + minYear;
                const month = Math.floor(Math.random() * 12) + 1;
                // 根据月份确定天数（简化处理，不考虑闰年）
                const daysInMonth = new Date(year, month, 0).getDate();
                const day = Math.floor(Math.random() * daysInMonth) + 1;
                
                return {
                    year: year.toString(),
                    month: month.toString().padStart(2, '0'),
                    day: day.toString().padStart(2, '0')
                };
            }
            
            // 生成顺序码（15-17位）
            function generateSequence(gender) {
                let sequence = Math.floor(Math.random() * 999).toString().padStart(3, '0');
                
                // 第17位表示性别：奇数男，偶数女
                if (gender !== 'any') {
                    let lastDigit = parseInt(sequence[2]);
                    if (gender === 'male' && lastDigit % 2 === 0) {
                        // 如果是偶数，加1变成奇数
                        lastDigit = (lastDigit + 1) % 10;
                        sequence = sequence.substring(0, 2) + lastDigit;
                    } else if (gender === 'female' && lastDigit % 2 !== 0) {
                        // 如果是奇数，加1变成偶数（如果加1后为10则减1）
                        lastDigit = (lastDigit + 1) % 10;
                        sequence = sequence.substring(0, 2) + lastDigit;
                    }
                }
                
                return sequence;
            }
            
            // 生成单个身份证号
            function generateIDCard(districtCode) {
                const gender = document.getElementById('gender').value;
                const ageRange = document.getElementById('age').value;
                
                // 生成出生日期
                const birthdate = generateBirthdate(ageRange);
                
                // 生成顺序码
                const sequence = generateSequence(gender);
                
                // 组合前17位
                const id17 = districtCode.substring(0, 6) + birthdate.year + birthdate.month + birthdate.day + sequence;
                
                // 计算校验码
                const checkDigit = calculateCheckDigit(id17);
                
                return id17 + checkDigit;
            }
            
            // 生成身份证号
            function generateIDCards() {
                idCardList.innerHTML = '';
                
                // 获取可用区县列表
                const availableDistricts = getAvailableDistricts();
                if (availableDistricts.length === 0) {
                    alert('请选择行政区划或输入6位区县代码');
                    return;
                }
                
                const count = parseInt(countSelect.value);
                const cards = [];
                
                for (let i = 0; i < count; i++) {
                    // 从可用区县中随机选择一个
                    const randomDistrict = availableDistricts[Math.floor(Math.random() * availableDistricts.length)];
                    const card = generateIDCard(randomDistrict);
                    cards.push(card);
                }
                
                cards.forEach(card => {
                    const li = document.createElement('li');
                    li.className = 'id-card-item';
                    
                    const span = document.createElement('span');
                    span.className = 'id-number';
                    span.textContent = card;
                    
                    const btn = document.createElement('button');
                    btn.className = 'copy-btn';
                    btn.innerHTML = '📋 复制';
                    
                    btn.addEventListener('click', function() {
                        navigator.clipboard.writeText(card).then(() => {
                            const originalHTML = btn.innerHTML;
                            btn.innerHTML = '✓ 已复制';
                            btn.classList.add('copied');
                            
                            setTimeout(() => {
                                btn.innerHTML = originalHTML;
                                btn.classList.remove('copied');
                            }, 2000);
                        });
                    });
                    
                    li.appendChild(span);
                    li.appendChild(btn);
                    idCardList.appendChild(li);
                });
                
                resultCount.textContent = cards.length + ' 条';
            }
            
            // 绑定生成按钮事件
            generateBtn.addEventListener('click', generateIDCards);
            
            // 初始选择一个省份（广东省）
            provinceSelect.value = '440000';
            provinceSelect.dispatchEvent(new Event('change'));
        });
    </script>
</body>
</html>